
<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>会员充值</el-breadcrumb-item>
        <el-breadcrumb-item>充值页会员排序</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @row-del="rowDel"
      >
        <template slot="last" slot-scope="scope">
          {{ scope.row.edit_time }}
          <el-tag>{{ scope.row.edit_admin_name }}</el-tag>
        </template>
         <!-- 自定义操作栏 -->
        <!-- <template slot-scope="scope" slot="menu">
           <el-button
           v-if="scope.row.flag==0"
            icon="el-icon-primary"
            type="text"
            size="small"
            @click.stop="updateFlagFn(scope)"
            >设为默认</el-button
          >
          <el-button
           v-else
            icon="el-icon-primary"
            type="text"
            size="small"
            @click.stop="updateFlagFn(scope)"
            >已设默认</el-button
          >
        </template> -->
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { appConfigVipPremium as baseURL , selectVersion,updateCoinAndVip,getCoinAndVipList,saveCoinAndVip} from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      page: {
        total: 0,
        pageSize: 10,
        // pageSizes:[1,2,3]
      },
      type: true,
      data: [],
      params: {},
      form: {},
      default: {
        orderByList: "sort&ASC,create_time&DESC",
      },
      option: {
        addBtn: true,
        editBtn: true,
        viewBtn: false,
        delBtn: true,
        addBtn: true,
        searchBtn: true,
        refreshBtn: true,
        excelBtn: false,
        column: [
          {
            label: "版本",
            prop: "app_version",
            type: "select",
            search: false,
            span: 12,
            placeholder: "请输入版本号",
            dicUrl: `${catUrl}/${selectVersion.selectVersion}`,
            props: {
              label: "app_version",
              value: "app_version",
            },
            dicFormatter: (res) => {
              return res.source;
            },
            rules: [
              {
                required: true,
                message: "版本号必须填写",
              },
            ],
          },
          {
            label: "用户端",
            prop: "user_port",
            type: "select",
            search: false,
            span:13,
            dicData: [
              {
                label: "Android",
                value: 0,
              },
              {
                label: "IOS",
                value: 1,
              },
            ],
            props: {
              label: "label",
              value: "value",
            },
            rules: [
              {
                required: true,
                message: "用户端必须填写",
              },
            ],
          },
           {
            label: "会员卡类型",
            prop: "vip_type",
            type: "select",
            search: false,
            placeholder: "会员卡类型",
            dicData: [
              {
                label: "月卡",
                value: '0',
              },
              {
                label: "季卡",
                value: '1',
              },
              {
                label: "年卡",
                value: '2',
              },
              {
                label: "连续包月",
                value: '3',
              },
              {
                label: "连续包季",
                value: '4',
              },
              {
                label: "连续包年",
                value: '5',
              },
            ],
            props: {
              label: "label",
              value: "value",
            },
            rules: [
              {
                required: true,
                message: "会员卡类型必须选择",
              },
            ],
          },
          {
            label: "充值金额",
            prop: "price",
            type: "input",
            search: false,
            placeholder: "请输入价格（元）",
            rules: [
              {
                required: true,
                message: "价格必须填写",
              },
            ],
            addDisplay: false,
            editDisplay: false,
          },
          {
            label: "排序",
            prop: "sort",
            type: "input",
          },
        ],
      },
    };
  },
  methods: {
    async updateFlagFn(scope){
       this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        type: "warning",
      })
        .then(async () => {
           let response = await common(
        baseURL.updateFlag,
       {vipId:scope.row.vip_id},
        null,
        "GET"
      );
        })
        .then(() => {
          this.getList();
        });
      
    },
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      console.log(getCoinAndVipList,'appConfigCoinVipappConfigCoinVipappConfigCoinVipappConfigCoinVip')
      let response = await common(
       getCoinAndVipList.getCoinAndVipList,
        { ...this.params },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    },
    /**保存 */
    async rowSave(row, done, loading) {
      delete row["id"];
      let userInfo = this.$store.state.user.userInfo;
      row.edit_admin_name = userInfo.username;
      row.edit_admin_id = userInfo.id;
      let data = await common(saveCoinAndVip.saveCoinAndVip, row, null, "POST");
      if (data == null) {
        loading();
        return;
      }
      this.getList();
      done();
    },
    /**修改 */
    async rowUpdate(row, index, done, loading) {
      let userInfo = this.$store.state.user.userInfo;
      row.edit_admin_name = userInfo.username;
      row.edit_admin_id = userInfo.id;
      let data = await common(updateCoinAndVip.updateCoinAndVip, row, null, "POST");
      if (data == null) {
        loading();
        return;
      }
      this.getList();
      done();
    },
    /**刷新 */
    refreshChange() {
      this.getList();
    },
    /**删除 */
    rowDel(row) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        type: "warning",
      })
        .then(async () => {
          let response = await common(
            updateCoinAndVip.delete,
            { id: row.id },
            null,
            "GET"
          );
      
        })
        .then(() => {
          this.getList();
        });
    },
    /**搜索 */
    searchChange(params, done) {
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  },
};
</script>